package ar.edu.utn.frba.dds.opendesigners.user;

import ar.edu.utn.frba.dds.opendesigners.RouteOption;
import ar.edu.utn.frba.dds.opendesigners.SearchParam;
import ar.edu.utn.frba.dds.opendesigners.SearchResponse;
import ar.edu.utn.frba.dds.opendesigners.exception.ExceptionBusiness;
import ar.edu.utn.frba.dds.opendesigners.exception.ExceptionInvalidAirline;
import ar.edu.utn.frba.dds.opendesigners.exception.ExceptionInvalidSeat;
import ar.edu.utn.frba.dds.opendesigners.stored.History;

public class User {
	private History history;
	private String nombre;
	private String apellido;
	private String dni;
	private SubscriptionType subscription;

	public User(String nombre, String apellido, String dni , SubscriptionType type) {
		this.nombre = nombre;
		this.apellido = apellido;
		this.dni = dni;
		this.subscription = type;
		this.history = new History();
	}

	public void setSubscription(SubscriptionType subscription) {
		this.subscription = subscription;
	}

	public void search(String stringSearch) {
		//TODO: Realizar, en caso de que la entrada sea por cadena (Este fue mi dilema por char, Matín jajaja)
	}
	
	public SearchResponse search(SearchParam searchParam ){ 
		this.history.recordLog(this.apellido, this.nombre, this.dni, searchParam);
		return this.subscription.search(searchParam);
	}
	
	public void buy(RouteOption option){
		try {			
			this.subscription.buy(option);
		} catch (ExceptionInvalidSeat invalidSeat) {
			throw new ExceptionBusiness("Asiento comprado o reservado");
		}catch (ExceptionInvalidAirline invalidAirline) {
			//Esta esta relacionada con la VISTA, mas que con el Usuario del sistema		
			throw new ExceptionBusiness("Aserolinea invalida");
		}
	}
}
